package test.event;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import game.Game;
import game.Player;
import game.event.Event;

import org.junit.Before;
import org.junit.Test;

public class StringOutputStringEvent {

	private Event<String> event;
	private String output;
	private Player player;

	@Before
	public void setUp() throws Exception {
		output = "";
		player = new Player("Seth");
		event = new Event<String>(player, "this is the event") {			
			@Override
			public void perform(Game game) {
				output = this.getEvent();				
			}
		};
	}

	@Test
	public void shouldNormalizeProperly() {
		long absTime = event.getTime();
		event.normalizeTS(absTime + 1000L);
		assertEquals(1000L, event.getTime());
	}

	@Test
	public void shouldHaveRecentTimestamp() {
		long currentTime = System.currentTimeMillis();
		assertTrue(currentTime >= event.getTime() && (currentTime - event.getTime()) < 5L );
	}

	@Test
	public void shouldRecordTheEvent() {
		assertEquals("this is the event", event.getEvent());
	}

	@Test
	public void shouldRecordTheOriginator() {
		assertEquals(player, event.getOriginator());
	}

	@Test
	public void shouldPerformStringOutput() {
		event.perform(null);
		assertTrue(output.equals(event.getEvent()));
	}

}
